package gui;

import enums.TestPanelEnum;
import enums.TextBundleEnum;
import enums.URLEnum;
import gui.filefilter.TSTFileFilter;
import gui.filefilter.TSTFileView;
import gui.other.Dimensions;
import gui.panel_new.OpenSavePanel;
import gui.panel_new.evaluation.exeptions.ExerciseNotBuiltException;
import gui.panel_new.evaluation.exeptions.PunctuationZeroException;
import gui.panel_new.evaluation.professor.*;
import internationalization.Internationalizer;
import j_util.Cronometer;
import j_util.Utiles;
import misc.BundlesProvider;
import misc.ExportDataPreferences;
import misc.Setup;
import model.eval.Test;
import model.eval.TestExcercise;
import org.jvnet.substance.SubstanceLookAndFeel;
import org.jvnet.substance.skin.SubstanceMistAquaLookAndFeel;
import org.jvnet.substance.skin.SubstanceModerateLookAndFeel;
import org.jvnet.substance.skin.SubstanceOfficeSilver2007LookAndFeel;
import org.jvnet.substance.skin.SubstanceSaharaLookAndFeel;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.ResourceBundle;
/*

    This file is part of Logica-Logike.

    Logica-Logike is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation version 3 of the License.

    Logica-Logike is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Logica-Logike.  If not, see <http://www.gnu.org/licenses/>.

 */
/**
 * Clase que contiene el main para la parte de creacion de evaluaciones y creacion de conexion de servidor;
 *
 * @author Jose Martin Rozanec;
 */
public class ServerTestFrame {

    public static void main(String[] args) {
        Setup.setupServer(false);
        Internationalizer.setSpanish();
        final ResourceBundle textBundle = BundlesProvider.getBundle(URLEnum.TEXT_BUNDLE);
        JFrame.setDefaultLookAndFeelDecorated(true);
        try {
            UIManager.setLookAndFeel(new SubstanceOfficeSilver2007LookAndFeel());
        } catch (Exception e) {
            System.out.println("Substance OfficeSilver2007 failed to initialize");
        }
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                /*Components initialization*/
                ExportDataPreferences exportPreferences=new ExportDataPreferences();
                final Test test = new Test();
                final TestOverviewPanel overviewPanel;
                final JButton saveAsButton = new JButton(Utiles.createImageIcon(URLEnum.getReference(URLEnum.SAVE_AS)));
                final JButton openButton = new JButton(Utiles.createImageIcon(URLEnum.getReference(URLEnum.OPEN)));
                final JFileChooser fileChooser = new JFileChooser();
                fileChooser.setFileFilter(new TSTFileFilter());
                fileChooser.setFileView(new TSTFileView());

                final Cronometer cronometer = new Cronometer();//todo ver si sirve para algo...
                final CardLayout excercisesCardLayout = new CardLayout();
                final JPanel excercisesPanel = new JPanel(excercisesCardLayout);
                final CreateExercisePanel excercisePanels[] = new CreateExercisePanel[9];

                openButton.setEnabled(false);

                final JFrame mainFrame = new JFrame();
                final JToolBar toolBar = new JToolBar();
                toolBar.setFloatable(false);
                toolBar.setVisible(true);

                final JLabel exerciseLabel =new JLabel(Utiles.createImageIcon(URLEnum.getReference(URLEnum.EJERCICIO_SERVER))); 
//                        new JLabel("Ejercicio: ");
                exerciseLabel.setFont(new Font("Tahoma", 1, 12));
//                new JLabel(Utiles.createImageIcon(URLEnum.getReference(URLEnum.EJERCICIO_SERVER)));

                //todo en la parte de conexion ver de colocar el logo y todo lo de about como relleno!
                JButton createNewTest = new JButton(Utiles.createImageIcon(URLEnum.getReference(URLEnum.NEW_TEST)));
                final JButton previousButton = new JButton(Utiles.createImageIcon(URLEnum.getReference(URLEnum.PREVIOUS_EXERCISE)));
                previousButton.setEnabled(false);
                final JButton deleteCurrentExcercise = new JButton(Utiles.createImageIcon(URLEnum.getReference(URLEnum.DELETE_CURRENT_EXERCISE)));
                deleteCurrentExcercise.setEnabled(false);
                final JButton nextButton = new JButton(Utiles.createImageIcon(URLEnum.getReference(URLEnum.NEXT_EXERCISE)));
                nextButton.setEnabled(false);
                final JButton addExcerciseButton = new JButton(Utiles.createImageIcon(URLEnum.getReference(URLEnum.ADD_EXCERCISE)));

                final JComboBox combo = new JComboBox();
                combo.addItem(textBundle.getString(TextBundleEnum.OPOSICION.toString()));
                combo.addItem(textBundle.getString(TextBundleEnum.VIOLACIONES_SILOGISMO.toString()));
                combo.addItem(textBundle.getString(TextBundleEnum.REDUCCION_DE_MODOS.toString()));
                combo.addItem(textBundle.getString(TextBundleEnum.MULTIPLE_CHOICE.toString()));
                combo.addItem(textBundle.getString(TextBundleEnum.TABLA_VERDAD.toString()));
                combo.addItem(textBundle.getString(TextBundleEnum.DIAGRAMAS_VENN.toString()));
                combo.addItem(textBundle.getString(TextBundleEnum.ANALIZAR_SILOGISMO.toString()));
                combo.addItem(textBundle.getString(TextBundleEnum.CREAR_SILOGISMO.toString()));
                combo.addItem(textBundle.getString(TextBundleEnum.CREAR_POLISILOGISMO.toString()));

                final JRadioButton office2007RadioButton = createLFRadioButton(mainFrame, new SubstanceOfficeSilver2007LookAndFeel(), 1);
                office2007RadioButton.setSelected(true);
                final JRadioButton aquaRadioButton = createLFRadioButton(mainFrame, new SubstanceMistAquaLookAndFeel(), 2);
                final JRadioButton saharaRadioButton = createLFRadioButton(mainFrame, new SubstanceSaharaLookAndFeel(), 3);
                final JRadioButton moderateRadioButton = createLFRadioButton(mainFrame, new SubstanceModerateLookAndFeel(), 4);

                ButtonGroup radioButtonGroup = new ButtonGroup();
                radioButtonGroup.add(office2007RadioButton);
                radioButtonGroup.add(aquaRadioButton);
                radioButtonGroup.add(saharaRadioButton);
                radioButtonGroup.add(moderateRadioButton);

                final JTabbedPane tabbedPane = new JTabbedPane();
                final TestOverviewProfessorPanel connectPanel = new TestOverviewProfessorPanel(saveAsButton, openButton, fileChooser, tabbedPane,exportPreferences);
                connectPanel.auxSetConnectionValues();//todo delete

                CreateOposicionEvaluationPanel oposicionPanel = new CreateOposicionEvaluationPanel(saveAsButton, openButton, fileChooser);
                CreateSylogismViolationPanel sylogismViolationsPanel =
                        new CreateSylogismViolationPanel(saveAsButton, openButton, fileChooser);
                SylogismCreateReducirModosPanel sylogismReducirModosPanel =
                        new SylogismCreateReducirModosPanel(saveAsButton, openButton, fileChooser);
                CreateMChoicePanel mChoicePanel = new CreateMChoicePanel(saveAsButton, openButton, fileChooser);
                CreateTruthTablePanel truthTablePanel = new CreateTruthTablePanel(saveAsButton, openButton, fileChooser);
                CreateVennPanel vennPanel = new CreateVennPanel(saveAsButton,openButton,fileChooser);
                CreateSylogismAnalysisPanel sylogismAnalysisPanel =
                        new CreateSylogismAnalysisPanel(
                                saveAsButton, openButton, fileChooser);
                CreateSylogismFromParametersPanel sylogismFromParametersPanel =
                        new CreateSylogismFromParametersPanel(saveAsButton,openButton,fileChooser);
                CreatePolisilogismoPanel createPolisilogismoPanel =
                        new CreatePolisilogismoPanel(saveAsButton,openButton,fileChooser);

                excercisePanels[0] = oposicionPanel;
                excercisePanels[1] = sylogismViolationsPanel;
                excercisePanels[2] = sylogismReducirModosPanel;
                excercisePanels[3] = mChoicePanel;
                excercisePanels[4] = truthTablePanel;
                excercisePanels[5] = vennPanel;
                excercisePanels[6] = sylogismAnalysisPanel;
                excercisePanels[7] = sylogismFromParametersPanel;
                excercisePanels[8] = createPolisilogismoPanel;

                excercisesPanel.add(oposicionPanel, TestPanelEnum.OPOSICION.toString());
                excercisesPanel.add(sylogismViolationsPanel, TestPanelEnum.VIOLACIONES_SILOGISMO.toString());
                excercisesPanel.add(sylogismReducirModosPanel, TestPanelEnum.REDUCCION_MODOS.toString());
                excercisesPanel.add(mChoicePanel, TestPanelEnum.MULTIPLE_CHOICE.toString());
                excercisesPanel.add(truthTablePanel, TestPanelEnum.TRUTH_TABLE.toString());
                excercisesPanel.add(vennPanel, TestPanelEnum.VENN.toString());
                excercisesPanel.add(sylogismAnalysisPanel, TestPanelEnum.ANALISIS_SILOGISMO.toString());
                excercisesPanel.add(sylogismFromParametersPanel, TestPanelEnum.CREAR_SILOGISMO.toString());
                excercisesPanel.add(createPolisilogismoPanel, TestPanelEnum.CREAR_POLISILOGISMO.toString());

                nextButton.setEnabled(false);
                previousButton.setEnabled(false);
                deleteCurrentExcercise.setEnabled(false);
                addExcerciseButton.setEnabled(false);
                combo.setEnabled(false);
                exerciseLabel.setEnabled(false);

                tabbedPane.addTab(textBundle.getString(TextBundleEnum.CONNECTION.toString()), null, connectPanel);
                tabbedPane.addTab(textBundle.getString(TextBundleEnum.EXCERCISE.toString()), null, excercisesPanel);
                overviewPanel = new TestOverviewPanel(saveAsButton, openButton, fileChooser);
                tabbedPane.addTab(textBundle.getString(TextBundleEnum.TEST_OVERVIEW.toString()), null, overviewPanel);
                connectPanel.refreshOpenSaveButtons();
                tabbedPane.addChangeListener(new ChangeListener() {
                    public void stateChanged(ChangeEvent e) {
                        if (((JTabbedPane) e.getSource()).getSelectedIndex() != 1) {
                            nextButton.setEnabled(false);
                            previousButton.setEnabled(false);
                            deleteCurrentExcercise.setEnabled(false);
                            addExcerciseButton.setEnabled(false);
                            combo.setEnabled(false);
                            exerciseLabel.setEnabled(false);
                        } else {
                            nextButton.setEnabled(true);
                            previousButton.setEnabled(true);
                            if (office2007RadioButton.getBackground() == Color.BLUE) {
                                deleteCurrentExcercise.setEnabled(true);
                            }
                            addExcerciseButton.setEnabled(true);
                            combo.setEnabled(true);
                            exerciseLabel.setEnabled(true);
                        }

                        if (((JTabbedPane) e.getSource()).getSelectedComponent().getClass().toString().equals("class javax.swing.JPanel")) {
                            excercisePanels[combo.getSelectedIndex()].refreshOpenSaveButtons();
                        } else {
//                            if(((JTabbedPane) e.getSource()).getSelectedComponent().getClass().toString().equals("class gui.panel_new.evaluation.professor.StudentMarksPanel")){
//
//                            }else{
                                ((OpenSavePanel) ((JTabbedPane) e.getSource()).getSelectedComponent()).refreshOpenSaveButtons();
//                            }
                        }
                    }
                });

                /*      END OF INITIALIZATION - ADDING ACTION LISTENERS       */
                final String[] yesNoOptions = new String[]{
                        textBundle.getString(TextBundleEnum.YES.toString()),
                        textBundle.getString(TextBundleEnum.NO.toString())
                };
                createNewTest.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        int option = JOptionPane.showOptionDialog(mainFrame,
                                textBundle.getString(TextBundleEnum.WARNING_NEW_TEST_WITHOUT_SAVING.toString())
                                , "", JOptionPane.YES_NO_OPTION,
                                JOptionPane.WARNING_MESSAGE, null, yesNoOptions, yesNoOptions[1]);

                        if (option == JOptionPane.YES_OPTION) {
                            test.reset();
                            overviewPanel.setTest(test);
                            office2007RadioButton.setBackground(new Color(-789003));
                            aquaRadioButton.setBackground(new Color(-789003));
                            saharaRadioButton.setBackground(new Color(-789003));
                            moderateRadioButton.setBackground(new Color(-789003));
                            deleteCurrentExcercise.setEnabled(false);
                        }
                    }
                });
                previousButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        int option = JOptionPane.YES_OPTION;
                        if (office2007RadioButton.getBackground() != Color.BLUE) {
                            option = JOptionPane.showOptionDialog(mainFrame,
                                    textBundle.getString(
                                            TextBundleEnum.WARNING_EXCERCISE_NOT_COMPLETE_LOOSE_INFO.toString()), "",
                                    JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE,
                                    null, yesNoOptions, yesNoOptions[1]);
                        }

                        if (option == JOptionPane.YES_OPTION) {
                            TestExcercise excercise = test.previous();
                            excercisesCardLayout.show(excercisesPanel, excercise.getPanelEnum().toString());
                            setExercisePanelInfo(excercise, excercisePanels);
                            office2007RadioButton.setBackground(Color.BLUE);
                            aquaRadioButton.setBackground(Color.BLUE);
                            saharaRadioButton.setBackground(Color.BLUE);
                            moderateRadioButton.setBackground(Color.BLUE);
                            deleteCurrentExcercise.setEnabled(true);
                        }
                    }
                });
                deleteCurrentExcercise.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        if (office2007RadioButton.getBackground() == Color.BLUE) {
                            test.deleteCurrentExcercise();
                            TestExcercise excercise = test.getCurrent();
                            excercisesCardLayout.show(excercisesPanel, excercise.getPanelEnum().toString());
                            setExercisePanelInfo(excercise, excercisePanels);
                            overviewPanel.setTest(test);
                            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),
                                    textBundle.getString(TextBundleEnum.WARNING_DELETED_OK.toString()));
                        }
                    }
                });
                nextButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        int option = JOptionPane.YES_OPTION;
                        if (office2007RadioButton.getBackground() != Color.BLUE) {
                            option = JOptionPane.showOptionDialog(mainFrame,
                                    textBundle.getString(
                                            TextBundleEnum.WARNING_EXCERCISE_NOT_COMPLETE_LOOSE_INFO.toString()), "",
                                    JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE,
                                    null, yesNoOptions, yesNoOptions[1]);
                        }

                        if (option == JOptionPane.YES_OPTION) {
                            TestExcercise excercise = test.next();
                            excercisesCardLayout.show(excercisesPanel, excercise.getPanelEnum().toString());
                            setExercisePanelInfo(excercise, excercisePanels);
                            office2007RadioButton.setBackground(Color.BLUE);
                            aquaRadioButton.setBackground(Color.BLUE);
                            saharaRadioButton.setBackground(Color.BLUE);
                            moderateRadioButton.setBackground(Color.BLUE);
                            deleteCurrentExcercise.setEnabled(true);
                        }
                    }
                });
                addExcerciseButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        TestExcercise exercise = getExcercise(excercisePanels, combo.getSelectedIndex());
                        if (exercise != null) {
                            test.addExcercise(exercise);
                            overviewPanel.setTest(test);
//                            addExcerciseButton.setForeground(new Color(150,255,120));
                            office2007RadioButton.setBackground(Color.GREEN);
                            aquaRadioButton.setBackground(Color.GREEN);
                            saharaRadioButton.setBackground(Color.GREEN);
                            moderateRadioButton.setBackground(Color.GREEN);
                            resetCurrentPanel(excercisePanels, combo.getSelectedIndex());
                        } else {
//                            addExcerciseButton.setBackground(new Color(255,150,120));
                            office2007RadioButton.setBackground(Color.RED);
                            aquaRadioButton.setBackground(Color.RED);
                            saharaRadioButton.setBackground(Color.RED);
                            moderateRadioButton.setBackground(Color.RED);
                        }

                        //todo habiendo guardado el ejercicio, hacer que todos los fields del panel se borren
                        //todo y que se notifique que se ha agregado exitosamente!
                        //todo ver de guardar la informacion antes de realizar el swith de panel
                    }
                });
                combo.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        office2007RadioButton.setBackground(new Color(-789003));
                        aquaRadioButton.setBackground(new Color(-789003));
                        saharaRadioButton.setBackground(new Color(-789003));
                        moderateRadioButton.setBackground(new Color(-789003));
                        deleteCurrentExcercise.setEnabled(false);

                        excercisePanels[combo.getSelectedIndex()].refreshOpenSaveButtons();

                        switch (combo.getSelectedIndex()) {
                            case 0:
                                excercisesCardLayout.show(excercisesPanel, TestPanelEnum.OPOSICION.toString());
                                break;
                            case 1:
                                excercisesCardLayout.show(excercisesPanel, TestPanelEnum.VIOLACIONES_SILOGISMO.toString());
                                break;
                            case 2:
                                excercisesCardLayout.show(excercisesPanel, TestPanelEnum.REDUCCION_MODOS.toString());
                                break;
                            case 3:
                                excercisesCardLayout.show(excercisesPanel, TestPanelEnum.MULTIPLE_CHOICE.toString());
                                break;
                            case 4:
                                excercisesCardLayout.show(excercisesPanel, TestPanelEnum.TRUTH_TABLE.toString());
                                break;
                            case 5:
                                excercisesCardLayout.show(excercisesPanel, TestPanelEnum.VENN.toString());
                                break;
                            case 6:
                                excercisesCardLayout.show(excercisesPanel, TestPanelEnum.ANALISIS_SILOGISMO.toString());
                                break;
                            case 7:
                                excercisesCardLayout.show(excercisesPanel, TestPanelEnum.CREAR_SILOGISMO.toString());
                                break;
                            case 8:
                                excercisesCardLayout.show(excercisesPanel, TestPanelEnum.CREAR_POLISILOGISMO.toString());
                                break;
                        }
                    }
                });
                /*      END OF ACTION LISTENERS - ADDING COMPONENTS TO TOOLBAR       */

                toolBar.add(createNewTest);
                toolBar.add(openButton);
                toolBar.add(saveAsButton);
                toolBar.add(exerciseLabel);
                toolBar.add(previousButton);
                toolBar.add(deleteCurrentExcercise);
                toolBar.add(nextButton);
                toolBar.add(addExcerciseButton);
                toolBar.add(combo);
                toolBar.add(office2007RadioButton);
                toolBar.add(aquaRadioButton);
                toolBar.add(saharaRadioButton);
                toolBar.add(moderateRadioButton);

                /*      END OF ADDING COMPONENTS TO TOOLBAR - MAINFRAME SETTINGS       */

                mainFrame.add(toolBar, BorderLayout.NORTH);
                mainFrame.add(tabbedPane);

                mainFrame.setSize(700, Dimensions.FRAME_HEIGHT);
                mainFrame.setTitle(textBundle.getString(TextBundleEnum.LOGICA.toString()) + " " +
                        textBundle.getString(TextBundleEnum.VERSION_NUMERO.toString()));
                mainFrame.setIconImage(Utiles.createImageIcon(URLEnum.getReference(URLEnum.LOGICA_ICON)).getImage());
                mainFrame.setResizable(false);

                switch (readLookAndFeelConfig()) {
                    case 2:
                        setLookAndFeel(aquaRadioButton, new SubstanceMistAquaLookAndFeel());
                        break;
                    case 3:
                        setLookAndFeel(saharaRadioButton, new SubstanceSaharaLookAndFeel());
                        break;
                    case 4:
                        setLookAndFeel(moderateRadioButton, new SubstanceModerateLookAndFeel());
                        break;
                }

                mainFrame.setVisible(true);
                mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            }
        });
    }

    /**
     * Escribe un archivo de configuracion en el que especifica el look and feel usado;
     *
     * @param lookAndFeel;
     */
    public static void writeLookAndFeelConfig(int lookAndFeel) {
        try {
            RandomAccessFile configFile = new RandomAccessFile(URLEnum.getReference(URLEnum.CONFIG_FILE), "rw");
            configFile.writeInt(lookAndFeel);
            configFile.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * Lee el archivo de configuracion y establece el look & feel utilizado por ultima vez;
     *
     * @return int - look and feel;
     */
    public static int readLookAndFeelConfig() {
        try {
            RandomAccessFile configFile = new RandomAccessFile(URLEnum.getReference(URLEnum.CONFIG_FILE), "rw");
            return configFile.readInt();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            writeLookAndFeelConfig(1);
        }
        return -1;
    }

    /**
     * Crea un radioButton cuya seleccion cambia el look and feel al especificado;
     *
     * @param frame;
     * @param lookAndFeel;
     * @param lookAndFeelID;
     * @return JRadioButton;
     */
    private static JRadioButton createLFRadioButton(final JFrame frame, final SubstanceLookAndFeel lookAndFeel, final int lookAndFeelID) {
        JRadioButton radioButton = new JRadioButton();
        radioButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    UIManager.setLookAndFeel(lookAndFeel);
                    frame.repaint();
                    writeLookAndFeelConfig(lookAndFeelID);
                } catch (UnsupportedLookAndFeelException e1) {
                    System.out.println("Failed " + lookAndFeel.getDescription());
                }
            }
        });
        return radioButton;
    }

    /**
     * Setea la informacion necesaria a un panel.
     * <p/>
     * excercisePanels[0]=oposicionPanel,
     * excercisePanels[1]=sylogismViolationsPanel,
     * excercisePanels[2]=sylogismReducirModosPanel,
     * excercisePanels[3]=createMChoicePanel;//todo completar
     *
     * @param testExcercise;
     * @param panels;
     */
    private static void setExercisePanelInfo(TestExcercise testExcercise, CreateExercisePanel[] panels) {
        System.out.println("ServerTestFrame:- " + testExcercise.getPanelEnum());//todo delete
        switch (testExcercise.getPanelEnum()) {
            case OPOSICION:
                panels[0].setExercise(testExcercise);
                break;
            case VIOLACIONES_SILOGISMO:
                panels[1].setExercise(testExcercise);
                break;
            case REDUCCION_MODOS:
                panels[2].setExercise(testExcercise);
                break;
            case MULTIPLE_CHOICE:
                panels[3].setExercise(testExcercise);
                break;
            case TRUTH_TABLE:
                panels[4].setExercise(testExcercise);
                break;
            case VENN:
                panels[5].setExercise(testExcercise);
                break;
            case ANALISIS_SILOGISMO:
                panels[6].setExercise(testExcercise);
                break;
            case CREAR_SILOGISMO:
                panels[7].setExercise(testExcercise);
                break;
            case CREAR_POLISILOGISMO:
                panels[8].setExercise(testExcercise);
                break;
        }
    }

    /**
     * Permite obtener el ejercicio propio del panel solicitado.
     * <p/>
     * excercisePanels[0]=oposicionPanel,
     * excercisePanels[1]=sylogismViolationsPanel,
     * excercisePanels[2]=sylogismReducirModosPanel,
     * excercisePanels[3]=createMChoicePanel;
     *
     * @param panels      - los paneles;
     * @param comboOption - opcion del panel;
     * @return TestExcercise;
     */
    private static TestExcercise getExcercise(CreateExercisePanel[] panels, int comboOption) {
        ResourceBundle textBundle = BundlesProvider.getBundle(URLEnum.TEXT_BUNDLE);
        try {
            return panels[comboOption].getExercise();
        } catch (ExerciseNotBuiltException e) {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),
                    textBundle.getString(TextBundleEnum.WARNING_EXCERCISE_NOT_COMPLETE.toString()), "",
                    JOptionPane.WARNING_MESSAGE);
        } catch (PunctuationZeroException e) {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),
                    textBundle.getString(TextBundleEnum.WARNING_SUMA_CERO.toString()),
                    "", JOptionPane.WARNING_MESSAGE);
        }
        return null;
    }

    /**
     * Resetea el panel actual;
     *
     * @param panels;
     * @param comboOption;
     */
    private static void resetCurrentPanel(CreateExercisePanel[] panels, int comboOption) {
        panels[comboOption].reset();
    }

    /**
     * Permite setear el look and feel;
     *
     * @param radioButton;
     * @param lookAndFeel;
     */
    private static void setLookAndFeel(JRadioButton radioButton, SubstanceLookAndFeel lookAndFeel) {
        radioButton.setSelected(true);
        try {
            UIManager.setLookAndFeel(lookAndFeel);
        } catch (UnsupportedLookAndFeelException e1) {
            System.out.println("Failed " + lookAndFeel.getDescription());
        }
    }
}
